//
//  MessageViewController.m
//  test1
//
//  Created by 衣尚品1 on 15/5/4.
//  Copyright (c) 2015年 衣尚品1. All rights reserved.
//

#import "MessageViewController.h"
#import "MessageCell.h"
#import "RCIM.h"
#import "RCChatViewController.h"

@interface MessageViewController (){
    NSMutableArray *teacherPic;
    NSMutableArray *teacherName;
    NSMutableArray *messageArr;
}

@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    teacherPic = [[NSMutableArray alloc] initWithObjects:@"teacher4.jpg",@"teacher5.jpg",@"teacher6.jpg", nil];
    teacherName = [[NSMutableArray alloc] initWithObjects:@"张冲",@"吴正利",@"陈国斌", nil];
    messageArr = [[NSMutableArray alloc] initWithObjects:@"几点上课？",@"上课的地点在哪里？",@"马上到", nil];
}

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 72;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentify = @"messageCell";
    
    UINib *nib = [UINib nibWithNibName:@"MessageCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:cellIdentify];
    
    MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    
    cell.nameLabel.text = teacherName[indexPath.row];
    cell.messageLabel.text = messageArr[indexPath.row];
    cell.pic.image = [UIImage imageNamed:teacherPic[indexPath.row]];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    [self performSegueWithIdentifier:@"gotoMessage" sender:self];
    
    [RCIM connectWithToken:@"eCauf2imkY+0nl7yAMbB4niPfKr/+taTIwNODqO7o6pxtt8w/VcnOhd7aCh+x+wrqwiNFOJJfoO88hF53jTBGg==" completion:^(NSString *userId) {
        
        RCChatViewController *chatViewController = [[RCIM sharedRCIM] createPrivateChat:@"2" title:teacherName[indexPath.row] completion:^{
        }];
        
        [self.navigationController pushViewController:chatViewController animated:YES
         ];
        
        self.tabBarController.tabBar.hidden = YES;
        
    } error:^(RCConnectErrorCode status) {
        
    }];

    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
